#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>

#define N 10

typedef void (*callback_t)();

void Worker()
{
    int cnt = 10;
    while(cnt)
    {
        printf("I am child process, pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt);
        sleep(1);
        cnt--;
    }

}


void createSubProcess(int n, callback_t cb)
{
    for(int i = 0;i < n; i++)
    {
        sleep(1);
        pid_t id = fork();
        if(id == 0)
        {
            //child
            printf("create child process success: %d\n", i);
            cb();
            exit(0);
        }
    }
}


int main()
{

    createSubProcess(N, Worker);
    //只有父进程走到这里
    sleep(100);
    return 0;
}
